import scala.collection.mutable.ArrayBuffer

// 欧拉项目第11题
object  max_num {
  def main(args: Array[String]): Unit = {
    val nrows = 20
    val ncols = 20
    val rows = Array.ofDim[String](nrows,ncols)

    val bufferdSource = io.Source.fromFile("E:\\scala_example\\src\\main\\scala\\data\\11.txt")
    var count = 0
    for (line <- bufferdSource.getLines) {
//      val cols = line.split(" ").map(_.trim)
//      print(s"${cols(0)}") // 输出文件的第一行，一行全部连接在一起

      rows(count) = line.split(" ").map(_.trim)
      count += 1

    }
    bufferdSource.close

    val numMax = getMaxNum(rows)
    println(numMax)

  }

//  def getMaxNum(vector:Array[Array[String]]) : Int = {
//    val numMaxArrayBuffer = ArrayBuffer[Int]()
//    for (x <- 0 to 3; y <- 0 to 3) {
//      var numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//      (x,y) match {
//        case _ if (x < 3 && y < 3) =>
//          val a1 = List(vector(x)(y).toInt,vector(x)(y+1).toInt,vector(x)(y+2).toInt,vector(x)(y+3).toInt)
//          val a2 = List(vector(x)(y).toInt,vector(x+1)(y).toInt,vector(x+2)(y).toInt,vector(x+3)(y).toInt)
//          val a3 = List(vector(x)(y).toInt,vector(x+1)(y+1).toInt,vector(x+2)(y+2).toInt,vector(x+3)(y+3).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//
//          println("1====================")
//          println("x: " + x + " " + "y: " + y)
//          println()
//          println("a1: " + a1)
//          println("a2: " + a2)
//          println("a3: " + a3)
//          println()
//          println("numRegionMaxArrayBuffer: " + numRegionMaxArrayBuffer)
//          println()
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//          println("2================================")
//
//          println("numMaxArrayBuffer: " + numMaxArrayBuffer)
//          println("3=================================")
//          println()
//
//
//
//        case _ if (x < 3 && y >=3 && y <= 16)  =>
//          println("4========")
//          val a1 = List(vector(x)(y).toInt,vector(x+1)(y).toInt,vector(x+2)(y).toInt,vector(x+3)(y).toInt)
//          val a2 = List(vector(x)(y).toInt,vector(x+1)(y+1).toInt,vector(x+2)(y+1).toInt,vector(x+3)(y+1).toInt)
//          val a3 = List(vector(x)(y).toInt,vector(x)(y-1).toInt,vector(x)(y-2).toInt,vector(x)(y-3).toInt)
//          val a4 = List(vector(x)(y).toInt,vector(x)(y+1).toInt,vector(x)(y+2).toInt,vector(x)(y+2).toInt)
//          val a5 = List(vector(x)(y).toInt,vector(x+1)(y-1).toInt,vector(x+2)(y-2).toInt,vector(x+3)(y-3).toInt)
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//          numRegionMaxArrayBuffer += a4
//          numRegionMaxArrayBuffer += a5
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//          numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//
//        case _ if x < 3 && y >= 17 =>
//          println("5==========")
//          val a1 = List(vector(x)(y).toInt,vector(x)(y-1).toInt,vector(x)(y-2).toInt,vector(x)(y-3).toInt)
//          val a2 = List(vector(x)(y).toInt,vector(x+1)(y-1).toInt,vector(x+2)(y-2).toInt,vector(x+3)(y-3).toInt)
//          val a3 = List(vector(x)(y).toInt,vector(x+1)(y).toInt,vector(x+2)(y).toInt,vector(x+3)(y).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//          numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//
//        case _ if x >= 3 && x <= 16 && y < 3 =>
//          println("6=========")
//          val a1 = List(vector(x)(y).toInt,vector(x-1)(y).toInt,vector(x-2)(y).toInt,vector(x-3)(y).toInt)
//          val a2 = List(vector(x)(y).toInt,vector(x+1)(y).toInt,vector(x+2)(y).toInt,vector(x+3)(y).toInt)
//          val a3 = List(vector(x)(y).toInt,vector(x)(y+1).toInt,vector(x)(y+2).toInt,vector(x)(y+3).toInt)
//          val a4 = List(vector(x)(y).toInt,vector(x-1)(y+1).toInt,vector(x-2)(y+2).toInt,vector(x-3)(y+3).toInt)
//          val a5 = List(vector(x)(y).toInt,vector(x+1)(y+1).toInt,vector(x+2)(y+2).toInt,vector(x+3)(y+3).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//          numRegionMaxArrayBuffer += a4
//          numRegionMaxArrayBuffer += a5
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//          numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//
//        case _ if x >= 3 && x <= 16 && y >= 3 && y <= 16 =>
//          println("7=========")
//          val a1 = List(vector(x)(y).toInt,vector(x-1)(y).toInt,vector(x-2)(y).toInt,vector(x-3)(y).toInt)
//          val a2 = List(vector(x)(y).toInt,vector(x+1)(y).toInt,vector(x+2)(y).toInt,vector(x+3)(y).toInt)
//          val a3 = List(vector(x)(y).toInt,vector(x)(y+1).toInt,vector(x)(y+2).toInt,vector(x)(y+3).toInt)
//          val a4 = List(vector(x)(y).toInt,vector(x)(y-1).toInt,vector(x)(y-2).toInt,vector(x)(y-3).toInt)
//          val a5 = List(vector(x)(y).toInt,vector(x-1)(y+1).toInt,vector(x-2)(y-2).toInt,vector(x-3)(y-3).toInt)
//          val a6 = List(vector(x)(y).toInt,vector(x-1)(y-1).toInt,vector(x-2)(y+2).toInt,vector(x-3)(y+3).toInt)
//          val a7 = List(vector(x)(y).toInt,vector(x+1)(y+1).toInt,vector(x+2)(y+2).toInt,vector(x+3)(y+3).toInt)
//          val a8 = List(vector(x)(y).toInt,vector(x+1)(y-1).toInt,vector(x+2)(y-2).toInt,vector(x+3)(y-2).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//          numRegionMaxArrayBuffer += a4
//          numRegionMaxArrayBuffer += a5
//          numRegionMaxArrayBuffer += a6
//          numRegionMaxArrayBuffer += a7
//          numRegionMaxArrayBuffer += a8
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//          numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//
//        case _ if x >= 3 && x <= 16 && y >=17 =>
//          println("8=========")
//          val a1 = List(vector(x)(y).toInt,vector(x)(y-1).toInt,vector(x)(y-2).toInt,vector(x)(y-3).toInt)
//          val a2 = List(vector(x)(y).toInt,vector(x-1)(y).toInt,vector(x-2)(y).toInt,vector(x-3)(y).toInt)
//          val a3 = List(vector(x)(y).toInt,vector(x+1)(y).toInt,vector(x+2)(y).toInt,vector(x+3)(y).toInt)
//          val a4 = List(vector(x)(y).toInt,vector(x-1)(y-1).toInt,vector(x-2)(y-2).toInt,vector(x-3)(y-3).toInt)
//          val a5 = List(vector(x)(y).toInt,vector(x+1)(y-1).toInt,vector(x+2)(y-2).toInt,vector(x+3)(y-3).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//          numRegionMaxArrayBuffer += a4
//          numRegionMaxArrayBuffer += a5
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//          numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//
//        case _ if x >= 17 && y < 3 =>
//          println("9==============")
//          val a1 = List(vector(x)(y).toInt,vector(x-1)(y).toInt,vector(x-2)(y).toInt,vector(x-3)(y).toInt)
//          val a2 = List(vector(x)(y).toInt,vector(x-1)(y+1).toInt,vector(x-2)(y+2).toInt,vector(x-3)(y+3).toInt)
//          val a3 = List(vector(x)(y).toInt,vector(x)(y+1).toInt,vector(x)(y+2).toInt,vector(x)(y+3).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//          numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//
//        case _ if x >= 17 && y >= 3 && y <= 16 =>
//          println("10===========")
//          val a1 = List(vector(x)(y).toInt,vector(x)(y-1).toInt,vector(x)(y-2).toInt,vector(x)(y-3).toInt)
//          val a2 = List(vector(x)(y).toInt,vector(x)(y+1).toInt,vector(x)(y+2).toInt,vector(x)(y+3).toInt)
//          val a3 = List(vector(x)(y).toInt,vector(x-1)(y-1).toInt,vector(x-2)(y-2).toInt,vector(x-3)(y-3).toInt)
//          val a4 = List(vector(x)(y).toInt,vector(x-1)(y+1).toInt,vector(x-2)(y+2).toInt,vector(x-3)(y+3).toInt)
//          val a5 = List(vector(x)(y).toInt,vector(x-1)(y).toInt,vector(x-2)(y).toInt,vector(x-3)(y).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//          numRegionMaxArrayBuffer += a4
//          numRegionMaxArrayBuffer += a5
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//          numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//
//        case _ if x >= 17 && y >= 17 =>
//          println("1111111")
//          val a1 = List(vector(x)(y).toInt,vector(x)(y-1).toInt,vector(x)(y-2).toInt,vector(x)(y-3).toInt)
//          val a2 = List(vector(x)(y).toInt,vector(x-1)(y-1).toInt,vector(x-2)(y-2).toInt,vector(x-3)(y-3).toInt)
//          val a3 = List(vector(x)(y).toInt,vector(x-1)(y).toInt,vector(x-2)(y).toInt,vector(x-3)(y).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//          numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//
//        case _ => None
//      }
//    }
//    numMaxArrayBuffer.sorted.last
//  }

//  def getMaxNum(vector:Array[Array[String]]) : Int = {
//    val numMaxArrayBuffer = ArrayBuffer[Int]()
//    for (x <- 0 to 19; y <- 0 to 19) {
//      var numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//      if(x < 3 && y < 3) {
//        val a1 = List(vector(x)(y).toInt,vector(x)(y+1).toInt,vector(x)(y+2).toInt,vector(x)(y+3).toInt)
//        val a2 = List(vector(x)(y).toInt,vector(x+1)(y).toInt,vector(x+2)(y).toInt,vector(x+3)(y).toInt)
//        val a3 = List(vector(x)(y).toInt,vector(x+1)(y+1).toInt,vector(x+2)(y+2).toInt,vector(x+3)(y+3).toInt)
//
//        numRegionMaxArrayBuffer += a1
//        numRegionMaxArrayBuffer += a2
//        numRegionMaxArrayBuffer += a3
//        numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//      } else if (x < 3 && y >=3 && y <= 16) {
//        val a1 = List(vector(x)(y).toInt,vector(x+1)(y).toInt,vector(x+2)(y).toInt,vector(x+3)(y).toInt)
//        val a2 = List(vector(x)(y).toInt,vector(x+1)(y+1).toInt,vector(x+2)(y+1).toInt,vector(x+3)(y+1).toInt)
//        val a3 = List(vector(x)(y).toInt,vector(x)(y-1).toInt,vector(x)(y-2).toInt,vector(x)(y-3).toInt)
//        val a4 = List(vector(x)(y).toInt,vector(x)(y+1).toInt,vector(x)(y+2).toInt,vector(x)(y+2).toInt)
//        val a5 = List(vector(x)(y).toInt,vector(x+1)(y-1).toInt,vector(x+2)(y-2).toInt,vector(x+3)(y-3).toInt)
//        numRegionMaxArrayBuffer += a1
//        numRegionMaxArrayBuffer += a2
//        numRegionMaxArrayBuffer += a3
//        numRegionMaxArrayBuffer += a4
//        numRegionMaxArrayBuffer += a5
//
//        numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//      } else if(x < 3 && y >= 17){
//        val a1 = List(vector(x)(y).toInt,vector(x)(y-1).toInt,vector(x)(y-2).toInt,vector(x)(y-3).toInt)
//        val a2 = List(vector(x)(y).toInt,vector(x+1)(y-1).toInt,vector(x+2)(y-2).toInt,vector(x+3)(y-3).toInt)
//        val a3 = List(vector(x)(y).toInt,vector(x+1)(y).toInt,vector(x+2)(y).toInt,vector(x+3)(y).toInt)
//
//        numRegionMaxArrayBuffer += a1
//        numRegionMaxArrayBuffer += a2
//        numRegionMaxArrayBuffer += a3
//
//        numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//        numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//      } else if(x >= 3 && x <= 16 && y < 3){
//        val a1 = List(vector(x)(y).toInt,vector(x-1)(y).toInt,vector(x-2)(y).toInt,vector(x-3)(y).toInt)
//        val a2 = List(vector(x)(y).toInt,vector(x+1)(y).toInt,vector(x+2)(y).toInt,vector(x+3)(y).toInt)
//        val a3 = List(vector(x)(y).toInt,vector(x)(y+1).toInt,vector(x)(y+2).toInt,vector(x)(y+3).toInt)
//        val a4 = List(vector(x)(y).toInt,vector(x-1)(y+1).toInt,vector(x-2)(y+2).toInt,vector(x-3)(y+3).toInt)
//        val a5 = List(vector(x)(y).toInt,vector(x+1)(y+1).toInt,vector(x+2)(y+2).toInt,vector(x+3)(y+3).toInt)
//
//        numRegionMaxArrayBuffer += a1
//        numRegionMaxArrayBuffer += a2
//        numRegionMaxArrayBuffer += a3
//        numRegionMaxArrayBuffer += a4
//        numRegionMaxArrayBuffer += a5
//
//        numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//        numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//      } else if(x >=3 && x <= 16 && y >= 3 && y <= 16){
//        val a1 = List(vector(x)(y).toInt,vector(x-1)(y).toInt,vector(x-2)(y).toInt,vector(x-3)(y).toInt)
//        val a2 = List(vector(x)(y).toInt,vector(x+1)(y).toInt,vector(x+2)(y).toInt,vector(x+3)(y).toInt)
//        val a3 = List(vector(x)(y).toInt,vector(x)(y+1).toInt,vector(x)(y+2).toInt,vector(x)(y+3).toInt)
//        val a4 = List(vector(x)(y).toInt,vector(x)(y-1).toInt,vector(x)(y-2).toInt,vector(x)(y-3).toInt)
//        val a5 = List(vector(x)(y).toInt,vector(x-1)(y+1).toInt,vector(x-2)(y-2).toInt,vector(x-3)(y-3).toInt)
//        val a6 = List(vector(x)(y).toInt,vector(x-1)(y-1).toInt,vector(x-2)(y+2).toInt,vector(x-3)(y+3).toInt)
//        val a7 = List(vector(x)(y).toInt,vector(x+1)(y+1).toInt,vector(x+2)(y+2).toInt,vector(x+3)(y+3).toInt)
//        val a8 = List(vector(x)(y).toInt,vector(x+1)(y-1).toInt,vector(x+2)(y-2).toInt,vector(x+3)(y-2).toInt)
//
//        numRegionMaxArrayBuffer += a1
//        numRegionMaxArrayBuffer += a2
//        numRegionMaxArrayBuffer += a3
//        numRegionMaxArrayBuffer += a4
//        numRegionMaxArrayBuffer += a5
//        numRegionMaxArrayBuffer += a6
//        numRegionMaxArrayBuffer += a7
//        numRegionMaxArrayBuffer += a8
//
//        numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//      } else if(x >=3 && x <= 16 && y >= 17) {
//        val a1 = List(vector(x)(y).toInt,vector(x)(y-1).toInt,vector(x)(y-2).toInt,vector(x)(y-3).toInt)
//        val a2 = List(vector(x)(y).toInt,vector(x-1)(y).toInt,vector(x-2)(y).toInt,vector(x-3)(y).toInt)
//        val a3 = List(vector(x)(y).toInt,vector(x+1)(y).toInt,vector(x+2)(y).toInt,vector(x+3)(y).toInt)
//        val a4 = List(vector(x)(y).toInt,vector(x-1)(y-1).toInt,vector(x-2)(y-2).toInt,vector(x-3)(y-3).toInt)
//        val a5 = List(vector(x)(y).toInt,vector(x+1)(y-1).toInt,vector(x+2)(y-2).toInt,vector(x+3)(y-3).toInt)
//
//        numRegionMaxArrayBuffer += a1
//        numRegionMaxArrayBuffer += a2
//        numRegionMaxArrayBuffer += a3
//        numRegionMaxArrayBuffer += a4
//        numRegionMaxArrayBuffer += a5
//
//        numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//      } else if(x >= 17 && y < 3) {
//        val a1 = List(vector(x)(y).toInt,vector(x-1)(y).toInt,vector(x-2)(y).toInt,vector(x-3)(y).toInt)
//        val a2 = List(vector(x)(y).toInt,vector(x-1)(y+1).toInt,vector(x-2)(y+2).toInt,vector(x-3)(y+3).toInt)
//        val a3 = List(vector(x)(y).toInt,vector(x)(y+1).toInt,vector(x)(y+2).toInt,vector(x)(y+3).toInt)
//
//        numRegionMaxArrayBuffer += a1
//        numRegionMaxArrayBuffer += a2
//        numRegionMaxArrayBuffer += a3
//
//        numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//      } else if(x >= 17 && y >=3 && y <= 16) {
//        val a1 = List(vector(x)(y).toInt,vector(x)(y-1).toInt,vector(x)(y-2).toInt,vector(x)(y-3).toInt)
//        val a2 = List(vector(x)(y).toInt,vector(x)(y+1).toInt,vector(x)(y+2).toInt,vector(x)(y+3).toInt)
//        val a3 = List(vector(x)(y).toInt,vector(x-1)(y-1).toInt,vector(x-2)(y-2).toInt,vector(x-3)(y-3).toInt)
//        val a4 = List(vector(x)(y).toInt,vector(x-1)(y+1).toInt,vector(x-2)(y+2).toInt,vector(x-3)(y+3).toInt)
//        val a5 = List(vector(x)(y).toInt,vector(x-1)(y).toInt,vector(x-2)(y).toInt,vector(x-3)(y).toInt)
//
//        numRegionMaxArrayBuffer += a1
//        numRegionMaxArrayBuffer += a2
//        numRegionMaxArrayBuffer += a3
//        numRegionMaxArrayBuffer += a4
//        numRegionMaxArrayBuffer += a5
//
//        numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//      } else {
//        val a1 = List(vector(x)(y).toInt,vector(x)(y-1).toInt,vector(x)(y-2).toInt,vector(x)(y-3).toInt)
//        val a2 = List(vector(x)(y).toInt,vector(x-1)(y-1).toInt,vector(x-2)(y-2).toInt,vector(x-3)(y-3).toInt)
//        val a3 = List(vector(x)(y).toInt,vector(x-1)(y).toInt,vector(x-2)(y).toInt,vector(x-3)(y).toInt)
//
//        numRegionMaxArrayBuffer += a1
//        numRegionMaxArrayBuffer += a2
//        numRegionMaxArrayBuffer += a3
//
//        numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//      }
//    }
//    println("numMaxArrayBuffer:" + numMaxArrayBuffer)
//    numMaxArrayBuffer.max
//  }

//  def getMaxNum(vector:Array[Array[String]]) : Int = {
//    val numMaxArrayBuffer = ArrayBuffer[Int]()
//    for (x <- 0 to 3; y <- 0 to 3) {
//      var numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//      if (x < 3) {
//        if (y < 3) {
//          val a1 = List(vector(x)(y).toInt, vector(x)(y + 1).toInt, vector(x)(y + 2).toInt, vector(x)(y + 3).toInt)
//          val a2 = List(vector(x)(y).toInt, vector(x + 1)(y).toInt, vector(x + 2)(y).toInt, vector(x + 3)(y).toInt)
//          val a3 = List(vector(x)(y).toInt, vector(x + 1)(y + 1).toInt, vector(x + 2)(y + 2).toInt, vector(x + 3)(y + 3).toInt)
//
//          println("1=====")
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//          println("x: " + x + " " + "y: " + y)
//          println("a1: " + a1)
//          println("a2: " + a2)
//          println("a3: " + a3)
//          println("numRegionMaxArrayBuffer: " + numRegionMaxArrayBuffer)
//          println()
//          println("1-2======")
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//          println("numMaxArrayBuffer: " + numMaxArrayBuffer)
//          println("1-3=========")
//          println()
//        } else if (y >= 3) {
//          if (y <= 16) {
//            print("2-1=======")
//            println()
//            val a1 = List(vector(x)(y).toInt, vector(x + 1)(y).toInt, vector(x + 2)(y).toInt, vector(x + 3)(y).toInt)
//            val a2 = List(vector(x)(y).toInt, vector(x + 1)(y + 1).toInt, vector(x + 2)(y + 1).toInt, vector(x + 3)(y + 1).toInt)
//            val a3 = List(vector(x)(y).toInt, vector(x)(y - 1).toInt, vector(x)(y - 2).toInt, vector(x)(y - 3).toInt)
//            val a4 = List(vector(x)(y).toInt, vector(x)(y + 1).toInt, vector(x)(y + 2).toInt, vector(x)(y + 2).toInt)
//            val a5 = List(vector(x)(y).toInt, vector(x + 1)(y - 1).toInt, vector(x + 2)(y - 2).toInt, vector(x + 3)(y - 3).toInt)
//            numRegionMaxArrayBuffer += a1
//            numRegionMaxArrayBuffer += a2
//            numRegionMaxArrayBuffer += a3
//            numRegionMaxArrayBuffer += a4
//            numRegionMaxArrayBuffer += a5
//
//            numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//            print("2-2=====")
//            println()
//          }
//        } else {
//          print("3-1=======")
//          val a1 = List(vector(x)(y).toInt, vector(x)(y - 1).toInt, vector(x)(y - 2).toInt, vector(x)(y - 3).toInt)
//          val a2 = List(vector(x)(y).toInt, vector(x + 1)(y - 1).toInt, vector(x + 2)(y - 2).toInt, vector(x + 3)(y - 3).toInt)
//          val a3 = List(vector(x)(y).toInt, vector(x + 1)(y).toInt, vector(x + 2)(y).toInt, vector(x + 3)(y).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//          numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//        }
//      } else if (x >= 3) if (x <= 16) {
//        if (y < 3) {
//          print("4-1=======")
//          val a1 = List(vector(x)(y).toInt, vector(x - 1)(y).toInt, vector(x - 2)(y).toInt, vector(x - 3)(y).toInt)
//          val a2 = List(vector(x)(y).toInt, vector(x + 1)(y).toInt, vector(x + 2)(y).toInt, vector(x + 3)(y).toInt)
//          val a3 = List(vector(x)(y).toInt, vector(x)(y + 1).toInt, vector(x)(y + 2).toInt, vector(x)(y + 3).toInt)
//          val a4 = List(vector(x)(y).toInt, vector(x - 1)(y + 1).toInt, vector(x - 2)(y + 2).toInt, vector(x - 3)(y + 3).toInt)
//          val a5 = List(vector(x)(y).toInt, vector(x + 1)(y + 1).toInt, vector(x + 2)(y + 2).toInt, vector(x + 3)(y + 3).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//          numRegionMaxArrayBuffer += a4
//          numRegionMaxArrayBuffer += a5
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//
//          numRegionMaxArrayBuffer = ArrayBuffer[List[Int]]()
//        } else if (y >= 3) {
//          if (y <= 16) {
//            print("5-1=======")
//            val a1 = List(vector(x)(y).toInt, vector(x - 1)(y).toInt, vector(x - 2)(y).toInt, vector(x - 3)(y).toInt)
//            val a2 = List(vector(x)(y).toInt, vector(x + 1)(y).toInt, vector(x + 2)(y).toInt, vector(x + 3)(y).toInt)
//            val a3 = List(vector(x)(y).toInt, vector(x)(y + 1).toInt, vector(x)(y + 2).toInt, vector(x)(y + 3).toInt)
//            val a4 = List(vector(x)(y).toInt, vector(x)(y - 1).toInt, vector(x)(y - 2).toInt, vector(x)(y - 3).toInt)
//            val a5 = List(vector(x)(y).toInt, vector(x - 1)(y + 1).toInt, vector(x - 2)(y - 2).toInt, vector(x - 3)(y - 3).toInt)
//            val a6 = List(vector(x)(y).toInt, vector(x - 1)(y - 1).toInt, vector(x - 2)(y + 2).toInt, vector(x - 3)(y + 3).toInt)
//            val a7 = List(vector(x)(y).toInt, vector(x + 1)(y + 1).toInt, vector(x + 2)(y + 2).toInt, vector(x + 3)(y + 3).toInt)
//            val a8 = List(vector(x)(y).toInt, vector(x + 1)(y - 1).toInt, vector(x + 2)(y - 2).toInt, vector(x + 3)(y - 2).toInt)
//
//            numRegionMaxArrayBuffer += a1
//            numRegionMaxArrayBuffer += a2
//            numRegionMaxArrayBuffer += a3
//            numRegionMaxArrayBuffer += a4
//            numRegionMaxArrayBuffer += a5
//            numRegionMaxArrayBuffer += a6
//            numRegionMaxArrayBuffer += a7
//            numRegionMaxArrayBuffer += a8
//
//            numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//          }
//        } else {
//          print("6-1=======")
//          val a1 = List(vector(x)(y).toInt, vector(x)(y - 1).toInt, vector(x)(y - 2).toInt, vector(x)(y - 3).toInt)
//          val a2 = List(vector(x)(y).toInt, vector(x - 1)(y).toInt, vector(x - 2)(y).toInt, vector(x - 3)(y).toInt)
//          val a3 = List(vector(x)(y).toInt, vector(x + 1)(y).toInt, vector(x + 2)(y).toInt, vector(x + 3)(y).toInt)
//          val a4 = List(vector(x)(y).toInt, vector(x - 1)(y - 1).toInt, vector(x - 2)(y - 2).toInt, vector(x - 3)(y - 3).toInt)
//          val a5 = List(vector(x)(y).toInt, vector(x + 1)(y - 1).toInt, vector(x + 2)(y - 2).toInt, vector(x + 3)(y - 3).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//          numRegionMaxArrayBuffer += a4
//          numRegionMaxArrayBuffer += a5
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//        }
//      } else if (x >= 17) {
//        if (y < 3) {
//          print("7-1=======")
//          val a1 = List(vector(x)(y).toInt, vector(x - 1)(y).toInt, vector(x - 2)(y).toInt, vector(x - 3)(y).toInt)
//          val a2 = List(vector(x)(y).toInt, vector(x - 1)(y + 1).toInt, vector(x - 2)(y + 2).toInt, vector(x - 3)(y + 3).toInt)
//          val a3 = List(vector(x)(y).toInt, vector(x)(y + 1).toInt, vector(x)(y + 2).toInt, vector(x)(y + 3).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//        } else if (y >= 3) {
//          if (y <= 16) {
//            print("8-1=======")
//            val a1 = List(vector(x)(y).toInt, vector(x)(y - 1).toInt, vector(x)(y - 2).toInt, vector(x)(y - 3).toInt)
//            val a2 = List(vector(x)(y).toInt, vector(x)(y + 1).toInt, vector(x)(y + 2).toInt, vector(x)(y + 3).toInt)
//            val a3 = List(vector(x)(y).toInt, vector(x - 1)(y - 1).toInt, vector(x - 2)(y - 2).toInt, vector(x - 3)(y - 3).toInt)
//            val a4 = List(vector(x)(y).toInt, vector(x - 1)(y + 1).toInt, vector(x - 2)(y + 2).toInt, vector(x - 3)(y + 3).toInt)
//            val a5 = List(vector(x)(y).toInt, vector(x - 1)(y).toInt, vector(x - 2)(y).toInt, vector(x - 3)(y).toInt)
//
//            numRegionMaxArrayBuffer += a1
//            numRegionMaxArrayBuffer += a2
//            numRegionMaxArrayBuffer += a3
//            numRegionMaxArrayBuffer += a4
//            numRegionMaxArrayBuffer += a5
//
//            numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//          }
//        } else if (y >= 17) {
//          print("9-1=======")
//          val a1 = List(vector(x)(y).toInt, vector(x)(y - 1).toInt, vector(x)(y - 2).toInt, vector(x)(y - 3).toInt)
//          val a2 = List(vector(x)(y).toInt, vector(x - 1)(y - 1).toInt, vector(x - 2)(y - 2).toInt, vector(x - 3)(y - 3).toInt)
//          val a3 = List(vector(x)(y).toInt, vector(x - 1)(y).toInt, vector(x - 2)(y).toInt, vector(x - 3)(y).toInt)
//
//          numRegionMaxArrayBuffer += a1
//          numRegionMaxArrayBuffer += a2
//          numRegionMaxArrayBuffer += a3
//
//          numMaxArrayBuffer += fourNumProductMax(numRegionMaxArrayBuffer)
//        }
//      }
//
//    }
//    numMaxArrayBuffer.max
//  }

  def getMaxNum(vector:Array[Array[String]]) : Int = {
    val numTotalMaxArrayBuffer = ArrayBuffer[Int]()
    val numTotalMaxArrayBuffer1 = ArrayBuffer[Int]()
    val numMaxArrayBuffer = ArrayBuffer[Int]()
    val numRegionMaxArrayBuffer = ArrayBuffer[Int]()
    val max_num1 = 0
    val tempArrayBuffer = ArrayBuffer[List[Int]]()
    val tempArrayBufferProduct = ArrayBuffer[Int]()
    for(i <- 1 to 2; j <- 1 to 2) {

      val a1 = vector(i)(j).toInt * vector(i+1)(j).toInt * vector(i+2)(j).toInt * vector(i+3)(j).toInt
      val a2 = vector(i)(j).toInt * vector(i)(j+1).toInt * vector(i)(j+2).toInt * vector(i+3)(j).toInt
      val a3 = vector(i)(j).toInt * vector(i+1)(j+1).toInt * vector(i+2)(j+2).toInt * vector(i+3)(j+3).toInt

      numMaxArrayBuffer += a1
      numMaxArrayBuffer += a2
      numMaxArrayBuffer += a3

      numRegionMaxArrayBuffer += numMaxArrayBuffer.max
//      println("numRegionMaxArrayBuffer: " + numRegionMaxArrayBuffer)
      numMaxArrayBuffer.clear
//      println()
// ================================================================================================================
      val aa1 = List(vector(i)(j).toInt,vector(i+1)(j).toInt,vector(i+2)(j).toInt,vector(i+3)(j).toInt)
      val aa2 = List(vector(i)(j).toInt,vector(i)(j+1).toInt,vector(i)(j+2).toInt , vector(i+3)(j).toInt)
      val aa3 = List(vector(i)(j).toInt ,vector(i+1)(j+1).toInt, vector(i+2)(j+2).toInt, vector(i+3)(j+3).toInt)

      tempArrayBuffer += aa1
      tempArrayBuffer += aa2
      tempArrayBuffer += aa3

      tempArrayBufferProduct += fourNumProductMax(tempArrayBuffer)

//      println("tempArrayBuffer: " + tempArrayBuffer)
//      println("tempArrayBufferProduct: " + tempArrayBufferProduct)
//      println()

      tempArrayBuffer.clear
    }


    numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
    tempArrayBufferProduct.clear

    numTotalMaxArrayBuffer += numRegionMaxArrayBuffer.max
    numRegionMaxArrayBuffer.clear


    for(i <- 1 to 2; j <- 17 to 19){
      val a1 = vector(i)(j).toInt * vector(i)(j-1).toInt * vector(i)(j-2).toInt * vector(i)(j-3).toInt
      val a2 = vector(i)(j).toInt * vector(i+1)(j).toInt * vector(i+2)(j).toInt * vector(i+3)(j).toInt
      val a3 = vector(i)(j).toInt * vector(i+1)(j-1).toInt * vector(i+2)(j-2).toInt * vector(i+3)(j-3).toInt

      numMaxArrayBuffer += a1
      numMaxArrayBuffer += a2
      numMaxArrayBuffer += a3

      numRegionMaxArrayBuffer += numMaxArrayBuffer.max
      numMaxArrayBuffer.clear
// =============================================================================================================
      val aa1 = List(vector(i)(j).toInt , vector(i)(j-1).toInt , vector(i)(j-2).toInt , vector(i)(j-3).toInt)
      val aa2 = List(vector(i)(j).toInt , vector(i+1)(j).toInt , vector(i+2)(j).toInt , vector(i+3)(j).toInt)
      val aa3 = List(vector(i)(j).toInt , vector(i+1)(j-1).toInt , vector(i+2)(j-2).toInt , vector(i+3)(j-3).toInt)

      tempArrayBuffer += aa1
      tempArrayBuffer += aa2
      tempArrayBuffer += aa3

      tempArrayBufferProduct += fourNumProductMax(tempArrayBuffer)
      numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
      tempArrayBuffer.clear
    }

    numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
    tempArrayBufferProduct.clear

    println("numRegionMaxArrayBuffer: " + numRegionMaxArrayBuffer)
    numTotalMaxArrayBuffer += numRegionMaxArrayBuffer.max
    numRegionMaxArrayBuffer.clear

    for(i <- 17 to 19; j <- 17 to 19) {
      val a1 = vector(i)(j).toInt * vector(i)(j-1).toInt * vector(i)(j-2).toInt * vector(i)(j-3).toInt
      val a2 = vector(i)(j).toInt * vector(i-1)(j).toInt * vector(i-2)(j).toInt * vector(i-3)(j).toInt
      val a3 = vector(i)(j).toInt * vector(i-1)(j-1).toInt * vector(i-2)(j-2).toInt * vector(i-3)(j-3).toInt

      numMaxArrayBuffer += a1
      numMaxArrayBuffer += a2
      numMaxArrayBuffer += a3

      numRegionMaxArrayBuffer += numMaxArrayBuffer.max
      numMaxArrayBuffer.clear

// ==============================================================================================================
      val aa1 = List(vector(i)(j).toInt , vector(i)(j-1).toInt , vector(i)(j-2).toInt , vector(i)(j-3).toInt)
      val aa2 = List(vector(i)(j).toInt , vector(i-1)(j).toInt , vector(i-2)(j).toInt , vector(i-3)(j).toInt)
      val aa3 = List(vector(i)(j).toInt , vector(i-1)(j-1).toInt , vector(i-2)(j-2).toInt , vector(i-3)(j-3).toInt)

      tempArrayBuffer += aa1
      tempArrayBuffer += aa2
      tempArrayBuffer += aa3

      tempArrayBufferProduct += fourNumProductMax(tempArrayBuffer)
      numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
      tempArrayBuffer.clear
    }

    numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
    tempArrayBufferProduct.clear

    numTotalMaxArrayBuffer += numRegionMaxArrayBuffer.max
    numRegionMaxArrayBuffer.clear
    for(i <- 17 to 19; j <- 1 to 2){
      val a1 = vector(i)(j).toInt * vector(i)(j+1).toInt * vector(i)(j+2).toInt * vector(i)(j+3).toInt
      val a2 = vector(i)(j).toInt * vector(i-1)(j).toInt * vector(i-2)(j).toInt * vector(i-3)(j).toInt
      val a3 = vector(i)(j).toInt * vector(i-1)(j+1).toInt * vector(i-2)(j+2).toInt * vector(i-3)(j+3).toInt

      numMaxArrayBuffer += a1
      numMaxArrayBuffer += a2
      numMaxArrayBuffer += a3

      numRegionMaxArrayBuffer += numMaxArrayBuffer.max
      numMaxArrayBuffer.clear
      
      //============================================================================================================
      val aa1 = List(vector(i)(j).toInt , vector(i)(j+1).toInt , vector(i)(j+2).toInt , vector(i)(j+3).toInt)
      val aa2 = List(vector(i)(j).toInt , vector(i-1)(j).toInt , vector(i-2)(j).toInt , vector(i-3)(j).toInt)
      val aa3 = List(vector(i)(j).toInt , vector(i-1)(j+1).toInt , vector(i-2)(j+2).toInt , vector(i-3)(j+3).toInt)

      tempArrayBuffer += aa1
      tempArrayBuffer += aa2
      tempArrayBuffer += aa3

      tempArrayBufferProduct += fourNumProductMax(tempArrayBuffer)
      numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
      tempArrayBuffer.clear
    }

    numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
    tempArrayBufferProduct.clear
    
    numTotalMaxArrayBuffer += numRegionMaxArrayBuffer.max
    numRegionMaxArrayBuffer.clear

    for(i <- 3 to 16; j <- 1 to 2) {
      val a1 = vector(i)(j).toInt * vector(i)(j+1).toInt * vector(i)(j+2).toInt * vector(i)(j+3).toInt
      val a2 = vector(i)(j).toInt * vector(i-1)(j).toInt * vector(i-2)(j).toInt * vector(i-3)(j).toInt
      val a3 = vector(i)(j).toInt * vector(i-1)(j+1).toInt * vector(i-2)(j+2).toInt * vector(i-3)(j+3).toInt
      val a4 = vector(i)(j).toInt * vector(i+1)(j).toInt * vector(i+2)(j).toInt * vector(i+3)(j).toInt
      val a5 = vector(i)(j).toInt * vector(i+1)(j+1).toInt * vector(i+2)(j+2).toInt * vector(i+3)(j+3).toInt

      numMaxArrayBuffer += a1
      numMaxArrayBuffer += a2
      numMaxArrayBuffer += a3
      numMaxArrayBuffer += a4
      numMaxArrayBuffer += a5

      numRegionMaxArrayBuffer += numMaxArrayBuffer.max
      numMaxArrayBuffer.clear
      
      //==============================================================================================================
      val aa1 = List(vector(i)(j).toInt , vector(i)(j+1).toInt , vector(i)(j+2).toInt , vector(i)(j+3).toInt)
      val aa2 = List(vector(i)(j).toInt , vector(i-1)(j).toInt , vector(i-2)(j).toInt , vector(i-3)(j).toInt)
      val aa3 = List(vector(i)(j).toInt , vector(i-1)(j+1).toInt , vector(i-2)(j+2).toInt , vector(i-3)(j+3).toInt)
      val aa4 = List(vector(i)(j).toInt , vector(i+1)(j).toInt , vector(i+2)(j).toInt , vector(i+3)(j).toInt)
      val aa5 = List(vector(i)(j).toInt , vector(i+1)(j+1).toInt , vector(i+2)(j+2).toInt , vector(i+3)(j+3).toInt)

      tempArrayBuffer += aa1
      tempArrayBuffer += aa2
      tempArrayBuffer += aa3
      tempArrayBuffer += aa4
      tempArrayBuffer += aa5

      tempArrayBufferProduct += fourNumProductMax(tempArrayBuffer)
      numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
      tempArrayBuffer.clear
    }

    numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
    tempArrayBufferProduct.clear
    
    numTotalMaxArrayBuffer += numRegionMaxArrayBuffer.max
    numRegionMaxArrayBuffer.clear

    for(i <- 3 to 16; j <- 17 to 19) {
      val a1 = vector(i)(j).toInt * vector(i)(j-1).toInt * vector(i)(j-2).toInt * vector(i)(j-3).toInt
      val a2 = vector(i)(j).toInt * vector(i-1)(j).toInt * vector(i-2)(j).toInt * vector(i-3)(j).toInt
      val a3 = vector(i)(j).toInt * vector(i-1)(j-1).toInt * vector(i-2)(j-2).toInt * vector(i-3)(j-3).toInt
      val a4 = vector(i)(j).toInt * vector(i+1)(j).toInt * vector(i+2)(j).toInt * vector(i+3)(j).toInt
      val a5 = vector(i)(j).toInt * vector(i+1)(j-1).toInt * vector(i+2)(j-2).toInt * vector(i+3)(j-3).toInt

      numMaxArrayBuffer += a1
      numMaxArrayBuffer += a2
      numMaxArrayBuffer += a3
      numMaxArrayBuffer += a4
      numMaxArrayBuffer += a5

      numRegionMaxArrayBuffer += numMaxArrayBuffer.max
      numMaxArrayBuffer.clear
      
      //=============================================================================================================
      val aa1 = List(vector(i)(j).toInt , vector(i)(j-1).toInt , vector(i)(j-2).toInt , vector(i)(j-3).toInt)
      val aa2 = List(vector(i)(j).toInt , vector(i-1)(j).toInt , vector(i-2)(j).toInt , vector(i-3)(j).toInt)
      val aa3 = List(vector(i)(j).toInt , vector(i-1)(j-1).toInt , vector(i-2)(j-2).toInt , vector(i-3)(j-3).toInt)
      val aa4 = List(vector(i)(j).toInt , vector(i+1)(j).toInt , vector(i+2)(j).toInt , vector(i+3)(j).toInt)
      val aa5 = List(vector(i)(j).toInt , vector(i+1)(j-1).toInt , vector(i+2)(j-2).toInt , vector(i+3)(j-3).toInt)

      tempArrayBuffer += aa1
      tempArrayBuffer += aa2
      tempArrayBuffer += aa3
      tempArrayBuffer += aa4
      tempArrayBuffer += aa5

      tempArrayBufferProduct += fourNumProductMax(tempArrayBuffer)
      numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
      tempArrayBuffer.clear
    }

    numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
    tempArrayBufferProduct.clear
    
    numTotalMaxArrayBuffer += numRegionMaxArrayBuffer.max
    numRegionMaxArrayBuffer.clear

    for(i <- 1 to 2; j <- 3 to 16) {
      val a1 = vector(i)(j).toInt * vector(i)(j-1).toInt * vector(i)(j-2).toInt * vector(i)(j-3).toInt
      val a2 = vector(i)(j).toInt * vector(i+1)(j).toInt * vector(i+2)(j).toInt * vector(i+3)(j).toInt
      val a3 = vector(i)(j).toInt * vector(i)(j+1).toInt * vector(i)(j+2).toInt * vector(i)(j+3).toInt
      val a4 = vector(i)(j).toInt * vector(i+1)(j+1).toInt * vector(i+2)(j+2).toInt * vector(i+3)(j+3).toInt
      val a5 = vector(i)(j).toInt * vector(i+1)(j-1).toInt * vector(i+2)(j-2).toInt * vector(i+3)(j-3).toInt

      numMaxArrayBuffer += a1
      numMaxArrayBuffer += a2
      numMaxArrayBuffer += a3
      numMaxArrayBuffer += a4
      numMaxArrayBuffer += a5

      numRegionMaxArrayBuffer += numMaxArrayBuffer.max
      numMaxArrayBuffer.clear
      
      // ==============================================================================================================
      val aa1 = List(vector(i)(j).toInt , vector(i)(j-1).toInt , vector(i)(j-2).toInt , vector(i)(j-3).toInt)
      val aa2 = List(vector(i)(j).toInt , vector(i+1)(j).toInt , vector(i+2)(j).toInt , vector(i+3)(j).toInt)
      val aa3 = List(vector(i)(j).toInt , vector(i)(j+1).toInt , vector(i)(j+2).toInt , vector(i)(j+3).toInt)
      val aa4 = List(vector(i)(j).toInt , vector(i+1)(j+1).toInt , vector(i+2)(j+2).toInt , vector(i+3)(j+3).toInt)
      val aa5 = List(vector(i)(j).toInt , vector(i+1)(j-1).toInt , vector(i+2)(j-2).toInt , vector(i+3)(j-3).toInt)

      tempArrayBuffer += aa1
      tempArrayBuffer += aa2
      tempArrayBuffer += aa3
      tempArrayBuffer += aa4
      tempArrayBuffer += aa5

      tempArrayBufferProduct += fourNumProductMax(tempArrayBuffer)
      numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
      tempArrayBuffer.clear
    }

    numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
    tempArrayBufferProduct.clear
    
    numTotalMaxArrayBuffer += numRegionMaxArrayBuffer.max
    numRegionMaxArrayBuffer.clear

    for(i <- 17 to 19; j <- 3 to 16) {
      val a1 = vector(i)(j).toInt * vector(i)(j-1).toInt * vector(i)(j-2).toInt * vector(i)(j-3).toInt
      val a2 = vector(i)(j).toInt * vector(i-1)(j).toInt * vector(i-2)(j).toInt * vector(i-3)(j).toInt
      val a3 = vector(i)(j).toInt * vector(i)(j+1).toInt * vector(i)(j+2).toInt * vector(i)(j+3).toInt
      val a4 = vector(i)(j).toInt * vector(i-1)(j+1).toInt * vector(i-2)(j+2).toInt * vector(i-3)(j+3).toInt
      val a5 = vector(i)(j).toInt * vector(i-1)(j-1).toInt * vector(i-2)(j-2).toInt * vector(i-3)(j-3).toInt

      numMaxArrayBuffer += a1
      numMaxArrayBuffer += a2
      numMaxArrayBuffer += a3
      numMaxArrayBuffer += a4
      numMaxArrayBuffer += a5

      numRegionMaxArrayBuffer += numMaxArrayBuffer.max
      numMaxArrayBuffer.clear
      
      // =============================================================================================================
      val aa1 = List(vector(i)(j).toInt , vector(i)(j-1).toInt , vector(i)(j-2).toInt , vector(i)(j-3).toInt)
      val aa2 = List(vector(i)(j).toInt , vector(i-1)(j).toInt , vector(i-2)(j).toInt , vector(i-3)(j).toInt)
      val aa3 = List(vector(i)(j).toInt , vector(i)(j+1).toInt , vector(i)(j+2).toInt , vector(i)(j+3).toInt)
      val aa4 = List(vector(i)(j).toInt , vector(i-1)(j+1).toInt , vector(i-2)(j+2).toInt , vector(i-3)(j+3).toInt)
      val aa5 = List(vector(i)(j).toInt , vector(i-1)(j-1).toInt , vector(i-2)(j-2).toInt , vector(i-3)(j-3).toInt)

      tempArrayBuffer += aa1
      tempArrayBuffer += aa2
      tempArrayBuffer += aa3
      tempArrayBuffer += aa4
      tempArrayBuffer += aa5

      tempArrayBufferProduct += fourNumProductMax(tempArrayBuffer)
      numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
      tempArrayBuffer.clear
    }

    numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
    tempArrayBufferProduct.clear

    numTotalMaxArrayBuffer += numRegionMaxArrayBuffer.max
    numRegionMaxArrayBuffer.clear

    for(i <- 3 to 16; j <- 3 to 16) {
      val a1 = vector(i)(j).toInt * vector(i)(j-1).toInt * vector(i)(j-2).toInt * vector(i)(j-3).toInt
      val a2 = vector(i)(j).toInt * vector(i-1)(j).toInt * vector(i-2)(j).toInt * vector(i-3)(j).toInt
      val a3 = vector(i)(j).toInt * vector(i)(j+1).toInt * vector(i)(j+2).toInt * vector(i)(j+3).toInt
      val a4 = vector(i)(j).toInt * vector(i-1)(j+1).toInt * vector(i-2)(j+2).toInt * vector(i-3)(j+3).toInt
      val a5 = vector(i)(j).toInt * vector(i-1)(j-1).toInt * vector(i-2)(j-2).toInt * vector(i-3)(j-3).toInt
      val a6 = vector(i)(j).toInt * vector(i+1)(j-1).toInt * vector(i+2)(j-2).toInt * vector(i+3)(j-3).toInt
      val a7 = vector(i)(j).toInt * vector(i+1)(j).toInt * vector(i+2)(j).toInt * vector(i+3)(j).toInt
      val a8 = vector(i)(j).toInt * vector(i+1)(j+1).toInt * vector(i+2)(j+2).toInt * vector(i+3)(j+3).toInt

      numMaxArrayBuffer += a1
      numMaxArrayBuffer += a2
      numMaxArrayBuffer += a3
      numMaxArrayBuffer += a4
      numMaxArrayBuffer += a5
      numMaxArrayBuffer += a6
      numMaxArrayBuffer += a7
      numMaxArrayBuffer += a8

      numRegionMaxArrayBuffer += numMaxArrayBuffer.max
      numMaxArrayBuffer.clear
      
      //===========================================================================================================

      val aa1 = List(vector(i)(j).toInt , vector(i)(j-1).toInt , vector(i)(j-2).toInt , vector(i)(j-3).toInt)
      val aa2 = List(vector(i)(j).toInt , vector(i-1)(j).toInt , vector(i-2)(j).toInt , vector(i-3)(j).toInt)
      val aa3 = List(vector(i)(j).toInt , vector(i)(j+1).toInt , vector(i)(j+2).toInt , vector(i)(j+3).toInt)
      val aa4 = List(vector(i)(j).toInt , vector(i-1)(j+1).toInt , vector(i-2)(j+2).toInt , vector(i-3)(j+3).toInt)
      val aa5 = List(vector(i)(j).toInt , vector(i-1)(j-1).toInt , vector(i-2)(j-2).toInt , vector(i-3)(j-3).toInt)
      val aa6 = List(vector(i)(j).toInt , vector(i+1)(j-1).toInt , vector(i+2)(j-2).toInt , vector(i+3)(j-3).toInt)
      val aa7 = List(vector(i)(j).toInt , vector(i+1)(j).toInt , vector(i+2)(j).toInt , vector(i+3)(j).toInt)
      val aa8 = List(vector(i)(j).toInt , vector(i+1)(j+1).toInt , vector(i+2)(j+2).toInt , vector(i+3)(j+3).toInt)

      tempArrayBuffer += aa1
      tempArrayBuffer += aa2
      tempArrayBuffer += aa3
      tempArrayBuffer += aa4
      tempArrayBuffer += aa5
      tempArrayBuffer += aa6
      tempArrayBuffer += aa7
      tempArrayBuffer += aa8

      tempArrayBufferProduct += fourNumProductMax(tempArrayBuffer)
      numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
      tempArrayBuffer.clear
    }

    numTotalMaxArrayBuffer1 += tempArrayBufferProduct.max
    println("numTotalMaxArrayBuffer1: " + numTotalMaxArrayBuffer1)
    println("numTotalMaxArrayBuffer1.max: " + numTotalMaxArrayBuffer1.max)

    numTotalMaxArrayBuffer += numRegionMaxArrayBuffer.max
    println("numTotalMaxArrayBuffer" + numTotalMaxArrayBuffer)
    numTotalMaxArrayBuffer.max
    
  }

  def fourNumProductMax(a1: ArrayBuffer[List[Int]]) : Int = {
    val numTempArrayBuffer = ArrayBuffer[Int]()
    for (i <- a1.indices) {
      numTempArrayBuffer += a1(i).head * a1(i)(1) * a1(i)(2) * a1(i)(3)
    }
    numTempArrayBuffer.max
  }
}
